//
//  CZMainViewController.swift
//  weibotet
//
//  Created by admin on 16-2-25.
//  Copyright (c) 2016年 Wind. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController{

    override func viewDidLoad() {
        super.viewDidLoad()
//自定义一个tabBar
        let mainTabBar = CZMainTarBarController()
    mainTabBar.backgroundColor = UIColor.blueColor()
        setValue(mainTabBar, forKey: "tabBar")
        //准备闭包
        mainTabBar.composeClosure = { ()  -> () in
            print("按钮点击调用闭包")
            
        }
        //新创建的table类是又自己管理的，而不是在APPdelegate里一堆代码
        addchildviewcontrollers()
        
      
     
            
            }
    
   
        
    

    
    func addchildviewcontrollers(){
        
        let tabBarVC = UITabBarController()
        
        //首页
        let homeVC = CZHomeViewController()
         addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        //信息
        let massageVC = CZMassageViewController()
       addChildViewController(massageVC, title: "信息", imageName: "tabbar_message_center")
        massageVC.view.backgroundColor = UIColor.redColor()
        //加号占位
          addChildViewController(UIViewController())
        //我
        let profilVC = CZProfileViewController()
//        profilVC.title = "我"
//        profilVC.tabBarItem.image = UIImage(named: "tabbar_profile")
        addChildViewController(profilVC, title: "我", imageName: "tabbar_profile")
        //发现
        let discoverVC = CZDiscoverViewController()
//        discoverVC.title = "发现"
//        discoverVC.tabBarItem.image = UIImage(named: "tabbar_discover")
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
//        tabBarVC.addChildViewController(homeVC)
        
//        tabBarVC.addChildViewController(massageVC)
//        tabBarVC.addChildViewController(profilVC)
//        tabBarVC.addChildViewController(discoverVC)
//        

    }
    
    //添加tabbar的子控制器
    func addChildViewController(Controller: UIViewController, title :String , imageName :String) {
        Controller.title = title
        Controller.tabBarItem.image = UIImage(named: imageName)
        
        //设置选中的item颜色
    
        let hightedImageName = imageName + "_highlighted"
        Controller.tabBarItem.selectedImage = UIImage(named : hightedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)//不要渲染

      Controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        "tabbar_discover"
     
        
        // 添加为tabBar的子控制器,并且包装导航控制器
        addChildViewController(UINavigationController (rootViewController: Controller))
    }
    
}


